package com.oscar.ehome.utils.webview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ProgressBar;

import com.oscar.ehome.R;

/****************************
   文件名:LoadWebView.java</br>
   @version 版本:1.0
   类描述:
 ****************************/
public class LoadWebView {

	public void loadWebView(WebView webView){
		
	}
	public View addView(Context context,String url){
		LayoutInflater inflater = (LayoutInflater) context.getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
				View view = inflater.inflate(R.layout.view_webview, null);
		WebView webView = (WebView) view.findViewById(R.id.view_webview_webview);
		final ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.view_webview_progressbar);
		progressBar.setVisibility(View.VISIBLE);
		// WebView加载web资源
				WebSettings webSettings = webView.getSettings();
				webSettings.setSavePassword(false);
				webSettings.setSaveFormData(true);// 保存表单数据
				webSettings.setJavaScriptEnabled(true);
				webSettings.setSupportZoom(true);       
				webSettings.setBuiltInZoomControls(true);
				webSettings
						.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);// 排版适应屏幕
				webSettings.setUseWideViewPort(true);// 可任意比例缩放
				webSettings.setLoadWithOverviewMode(true);
				// setUseWideViewPort方法设置webview推荐使用的窗口。setLoadWithOverviewMode方法是设置webview加载的页面的模式ist.get(position);
				webView.setInitialScale(25);
				webView.loadUrl(url);
				webView.setWebChromeClient(new WebChromeClient(){

				     public void onProgressChanged(WebView view, int progress) {
				    	 progressBar.setProgress(progress * 100);
				         if(progress == 100){
				        	 progressBar.setVisibility(View.GONE);
				         }
				     }
				});
				return view;
	}

}
